package com.kaiwukj.android.ufamily.app.base.review;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.kaiwukj.android.mcas.mvp.IPresenter;
import com.kaiwukj.android.mcas.mvp.IView;

import javax.inject.Inject;

public abstract class BaseMvpFragment<P extends IPresenter> extends BaseFragment implements IView {

    @Inject
    protected P mPresenter;

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        setupFragmentComponent(getAppComponent());
        if (mPresenter != null) {
            mPresenter.attachView(this);
            mPresenter.onStart();
        }
    }

    @Override
    public void onDetach() {
        if (mPresenter != null) {
            mPresenter.detachView();
            mPresenter = null;
        }
        super.onDetach();
    }

    @Override
    public void showLoading() {
        super.showLoading("正在加载...");
    }

    @Override
    public void showLoading(String loadingMsg) {
        super.showLoading(loadingMsg);
    }

    @Override
    public void hideLoading() {
        super.hideLoading();
    }

    @Override
    public void killMyself() {
        if (getActivity() != null) {
            getActivity().finish();
        }
    }

    @Override
    public void showMessage(@NonNull String message) {
        super.showMessage(message);
    }

    @Override
    public void onTaskErr(int taskId) {

    }

    @Override
    public void onTaskSuccess(int taskId) {

    }
}
